/*
 * Cell.h
 *
 *  Created on: Sep 23, 2011
 *      Author: Brandon
 */

#ifndef CELL_H_
#define CELL_H_

#include <MAUI/Image.h>
#include "MAHeaders.h"
#include <mavsprintf.h>

class Cell {
protected:

	bool m_isExposed;
	int m_xPos;
	int m_yPos;
	MAPoint2d m_position;
	MAUI::Image* m_image;
	MAUI::Widget* m_parent;
	bool m_isMine;
	int m_nearbyMineCount;

public:

	bool IsExposed(){
		return m_isExposed;
	}

	MAPoint2d GetLocation(){
		return m_position;
	}

	bool IsMine(){
		return m_isMine;
	}

	void SetMine(const bool& p_isMine){
		m_isMine = p_isMine;
	}

	void SetImage(const MAHandle& p_image){
		if(m_isMine){
			m_image->setResource(p_image);
		}
	}

	int NearbyMineCount(){
		return m_nearbyMineCount;
	}

	void IncrementNearbyMineCount(){
		m_nearbyMineCount++;
	}

	void ExposeCell(){

		m_isExposed = true;

		if(m_isMine){
				m_image->setResource(MINE);
				return;
			}

			MAHandle newImageHandle = ZERO;
			switch(m_nearbyMineCount){
				case 0:
					newImageHandle = ZERO;
					break;
				case 1:
					newImageHandle = ONE;
					break;
				case 2:
					newImageHandle = TWO;
					break;
				case 3:
					newImageHandle = THREE;
					break;
				case 4:
					newImageHandle = FOUR;
					break;
				case 5:
					newImageHandle = FIVE;
					break;
				case 6:
					newImageHandle = SIX;
					break;
				case 7:
					newImageHandle = SEVEN;
					break;
				case 8:
					newImageHandle = EIGHT;
					break;

			}

			m_image->setResource(newImageHandle);
	}

	Cell(int p_xPos, int p_yPos, MAUI::Widget* p_parent){
		m_xPos = p_xPos;
		m_yPos = p_yPos;
		m_position.x = p_xPos;
		m_position.y = p_yPos;
		m_parent = p_parent;
		m_isExposed = false;
		m_image = new MAUI::Image(m_xPos, m_yPos, 20, 20, m_parent, false, false, CELL);
		m_isMine = false;
		m_nearbyMineCount = 0;
	}

	bool OnClick(){
		if(m_isExposed){
			return false;
		}

		ExposeCell();
		return m_isMine;
	}
};



#endif /* CELL_H_ */
